const
    { exec, spawn } = require('child_process'),
    options = {
        timeout: 0,
        killSignal: 'SIGKILL',
        env: Object.assign({}, process.env, { num: 1000 })
    }
;

// const child = spawn('node', ['plus_one.js']);

// setInterval(function () {
//     var num = Math.floor(Math.random() * 1000);

//     child.stdin.write(num + '\n');
//     child.stdout.once('data', function (data) {
//         console.log('child replied to ' + num + ' with ' + data);
//     });
// }, 1000);

// child.stderr.on('data', function (err) {
//     process.stdout.write(err);
// });

// child.on('exit', function (code) {
//     console.log(code);
// });

// const child = spawn('ls', ['-la']);

// child.stdout.on('data', function (data) {
//     console.log(data.toString());
// });

const child = spawn('node', ['a.js']);

setTimeout(function () {
    // 向子进程发送信号, SIGKILL, SIGSTOP这两种信号不能被重写
    child.kill('SIGKILL');
}, 1000);

child.stdout.on('data', function (data) {
    console.log(data.toString());
});

child.on('exit', function (code, signal) {
    console.log(code, signal);
});

// process.on('SIGUSR2', function () {
//     console.log('SIGUSER2');
// });


const set = new Set(['red', 'green', 'blue']);
